package com.yoake.campus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yoake.campus.domain.vo.CampusContentVo;
import com.yoake.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoake.common.annotation.Log;
import com.yoake.common.core.controller.BaseController;
import com.yoake.common.core.domain.AjaxResult;
import com.yoake.common.enums.BusinessType;
import com.yoake.campus.domain.CampusContent;
import com.yoake.campus.service.ICampusContentService;
import com.yoake.common.utils.poi.ExcelUtil;
import com.yoake.common.core.page.TableDataInfo;

/**
 * 内容管理Controller
 * 
 * @author yoake
 * @date 2024-12-10
 */
@Slf4j
@RestController
@RequestMapping("/campus/content")
public class CampusContentController extends BaseController
{
    @Autowired
    private ICampusContentService campusContentService;

    /**
     * 查询内容管理列表
     */
    @PreAuthorize("@ss.hasPermi('campus:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(CampusContent campusContent)
    {
        startPage();
        List<CampusContentVo> list = campusContentService.selectCampusContentList(campusContent);
        return getDataTable(list);
    }
    
    /**
     * 获取内容管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:content:query')")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId)
    {
        return success(campusContentService.selectCampusContentVoByContentId(contentId));
    }

    /**
     * 新增内容管理
     */
    @PreAuthorize("@ss.hasPermi('campus:content:add')")
    @Log(title = "内容管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampusContentVo campusContentvo)
    {
        return toAjax(campusContentService.insertCampusContent(campusContentvo));
    }

    /**
     * 修改内容管理
     */
    @PreAuthorize("@ss.hasPermi('campus:content:edit')")
    @Log(title = "内容管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampusContentVo campusContentvo)
    {
        return toAjax(campusContentService.updateCampusContent(campusContentvo));
    }

    /**
     * 删除内容管理
     */
    @PreAuthorize("@ss.hasPermi('campus:content:remove')")
    @Log(title = "内容管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds)
    {
        return toAjax(campusContentService.deleteCampusContentByContentIds(contentIds));
    }
}
